package com.chilly.other.thread.pool;

import java.util.concurrent.ExecutorService;
import java.util.concurrent.LinkedBlockingQueue;
import java.util.concurrent.ThreadPoolExecutor;
import java.util.concurrent.TimeUnit;

/**
 * https://www.cnblogs.com/lifegoeson/p/13780720.html
 *
 * Created by Chilly Cui on 2020/12/15.
 */
public class ThreadPoolExecutorDemo {
    public static void main(String[] args) {
        ExecutorService executorService = new ThreadPoolExecutor(2, 5, 2L,
                TimeUnit.SECONDS, new LinkedBlockingQueue<>(3), new ThreadPoolExecutor.AbortPolicy());

        //模拟10个顾客办理业务
        try {
            for (int i = 0; i < 10; i++) {
                int finalI = i;
                executorService.execute(() -> {
                    System.out.println(Thread.currentThread().getName() + "---" + finalI + "号办理");
                });
            }
        } catch (Exception e) {
            e.printStackTrace();//执行到第8个就抛出异常了
        } finally {
            executorService.shutdown();
        }

    }
}
